<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String ctxPath = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ ctxPath + "/";
	String SYSTEM_NAME = "EZMES";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><%=SYSTEM_NAME%></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<base id="baseUrl" href="<%=basePath%>" />
<link href="<%=basePath%>css/bootstrap.min.css?v=3.4.0"
	rel="stylesheet">
<link href="<%=basePath%>css/font-awesome.min.css?v=4.3.0"
	rel="stylesheet">

<!-- Data Tables -->
<link
	href="<%=basePath%>css/plugins/dataTables/dataTables.bootstrap.css"
	rel="stylesheet">
<link href="<%=basePath%>css/plugins/dataTables/select.bootstrap.css"
	rel="stylesheet">
<link href="<%=basePath%>css/animate.min.css" rel="stylesheet">
<link href="<%=basePath%>css/style.min.css?v=3.0.0" rel="stylesheet">
</head>
<body>
	<!-- head star -->
	<!-- head end -->

	<!-- table star -->
	<div class="row col-lg-12">
		<div class="wrapper wrapper-content animated fadeInUp">
			<div class="ibox">
				<div class="ibox-title">
					<h5>新闻列表</h5>
					<div class="ibox-tools rboor">
						<a href="<%=basePath%>news/addNewsView"
							class="btn btn-primary btn-xs p310"><i class="im-plus"></i>
							添加新闻</a> <a href="javascript:toUpdateNewView()"
							class="btn btn-primary btn-xs p310"><i class="im-pencil2"></i>
							查看</a> <a href="javascript:gudongxinwen()"
							class="btn btn-primary btn-xs p310"><i class="im-remove4"></i>
							滚动新闻设置</a>
						<!--   <a href="projects.html" class="btn btn-primary btn-xs p310"><i class="im-spell-check"></i> 批量审核</a>-->
						<button id="tb-refresh" onclick="shuaxin()"
							class="btn btn-primary btn-xs p310">
							<i class="im-spinner10 fa-spin"></i> 刷新
						</button>
					</div>
				</div>
				<div style="text-align: center;" >
					新闻类型：	<select id="ntiD" onchange="changeNewsType()">
							<option value="">请选择</option>
							<c:forEach items="${nts}" var="nt">
								<option value="${nt.nt_id}">${nt.nt_name}</option>
            				</c:forEach>
						</select>
					</div>
				<div class="ibox-content">
					<table id="example" class="table table-striped table-bordered"
						cellspacing="0" width="100%">
						<thead>
							<tr>
								<th>图片</th>
								<th>标题</th>
								<th>状态</th>
								<th>是否轮播</th>
								<th>排序</th>
							</tr>
						</thead>
					</table>

				</div>

			</div>
		</div>
	</div>
<body>




	<!-- 全局js -->
	<script src="<%=basePath%>js/jquery-2.1.1.min.js"></script>
	<script src="<%=basePath%>js/bootstrap.min.js?v=3.4.0"></script>
	<script src="<%=basePath%>js/plugins/jeditable/jquery.jeditable.js"></script>
	<!-- Data Tables -->
	<script src="<%=basePath%>js/plugins/dataTables/jquery.dataTables.js"></script>
	<script
		src="<%=basePath%>js/plugins/dataTables/dataTables.bootstrap.js"></script>
	<script
		src="<%=basePath%>js/plugins/dataTables/dataTables.select.min.js"></script>
	<script src="<%=basePath%>js/plugins/layer/layer.js"></script>
	<!-- 自定义js -->
	<script src="<%=basePath%>js/content.min.js?v=1.0.0"></script>
</body>
<script type="text/javascript">
	var oTable;
	$(function() {
		initDataTables();
		rowListen();
	});
	function newsType(){
		 var param = {
			        "obj.name": name,
			        "obj.admin": admin
			   };
		 oTable.settings()[0].ajax.data = param;
	}
	function initDataTables() {
		oTable = $('#example')
				.DataTable(
						{
							"searching" : false,
							"serverSide" : true,
							"select" : true,
							"ajax" :{
								"url"  : $('#baseUrl').attr("href") + "news/query_allNewsByPage",
								"data" :{"news.nt_id":$("#ntiD").val()}
							},
							"columns" : [
									{
										"data" : "n_title_img",
										"render" : function(data, type, row) {
											if (data == null) {
												return null;
											} else {
												var img = "<img id=\"preview\" src=\""
														+ $('#baseUrl').attr(
																"href")
														+ data
														+ "\" width=\"100\" height=\"100\" style=\"display: block;border: 1px solid blue;\" />";
												return img;
											}
										}
									}, {
										"data" : "n_title",
										"render" : function(data, type, row) {
											if (data == null) {
												return "";
											} else {
												return data;
											}
										}
									}, {
										"data" : "n_status",
										"render" : function(data, type, row) {
											if (data == null)
												return "未发布";
											else if (data == 1)
												return "未发布";
											else if (data == 2)
												return "已发布";
										}
									},{
										"data" : "is_roll",
										"render" : function(data, type, row) {
											if (data == null)
												return "";
											else if (data == 1)
												return "是";
										}
									},{
										"data" : "n_sort",
										"render" : function(data, type, row) {
											if (data == null){
												var nid = row.n_id;
												return "<a href=\"javascript:void(0)\" onclick=\"updateSort(this,"+nid+")\">0</a>";
											}
											else{
												var nid = row.n_id;
												return "<a href=\"javascript:void(0)\" onclick=\"updateSort(this,"+nid+")\">"+data+"</a>";
											}
										}
									}  
									
									]
						});
	}
	function rowListen() {
		$('#example tbody').on('click', 'tr', function() {
			if ($(this).hasClass('selected')) {
				$(this).removeClass('selected');
			} else {
				oTable.$('tr.selected').removeClass('selected');
				$(this).addClass('selected');
			}
		});
	}
	function deleteUser() {
		var anSelected = fnGetSelected(oTable);
		if (anSelected.length == 0) {
			alert("请选择数据");
		} else {
			var rid = oTable.row('.selected').data().r_id;
			$.ajax({
				type : "post",
				data : {
					"role.r_id" : rid
				},
				url : $('#baseUrl').attr("href") + "role/delete_role",//URL,
				success : function(data) {
					if (data == true) {
						oTable.row('.selected').remove().draw(true);
					}
				}
			});
		}
	}
	function fnGetSelected(oTableLocal) {
		return oTableLocal.$('tr.selected');
	}
	function toAddRoleView() {
		layer.open({
			type : 2,
			title : '添加角色',
			area : [ '800px', '480px' ],
			fix : false, //不固定
			maxmin : true,
			content : $('#baseUrl').attr("href") + "role/toAddRoleView"
		});
	}
	function shuaxin() {
		oTable.draw();
	}
	function toUpdateUserView() {
		var anSelected = fnGetSelected(oTable);
		if (anSelected.length == 0) {
			alert("请选择数据");
		} else {
			var rid = oTable.row('.selected').data().r_id;
			layer.open({
				type : 2,
				title : '编辑角色',
				area : [ '800px', '480px' ],
				fix : false, //不固定
				maxmin : true,
				content : $('#baseUrl').attr("href")
						+ "role/toUpDateRoleView?role.r_id=" + rid
			});
		}
	}
	function toUpdateNewView() {
		var anSelected = fnGetSelected(oTable);
		if (anSelected.length == 0) {
			alert("请选择数据");
		} else {
			var nid = oTable.row('.selected').data().n_id;
			location.href = ($('#baseUrl').attr("href")
					+ "news/query_newsById?news.n_id=" + nid);
		}
	}
	function gudongxinwen(){
		var anSelected = fnGetSelected(oTable);
		if (anSelected.length == 0){
			alert("请选择数据！");
		}else{
			var nid = oTable.row('.selected').data().n_id;
			layer.confirm('', {
				  btn: ['设为轮播','取消轮播'] //按钮
				}, function(index){
					$.ajax({
						type:"post",
						data:{"news.n_id":nid},
						url :$('#baseUrl').attr("href")+"news/update_new_roll_yes",
						success:function(data){
							shuaxin();
							layer.close(index);
						}
					});
				}, function(index){
					$.ajax({
						type:"post",
						data:{"news.n_id":nid},
						url :$('#baseUrl').attr("href")+"news/update_new_roll_no",
						success:function(data){
							shuaxin();
							layer.close(index);
						}
					});
				});
		} 
	}
	function changeNewsType(){
		var param = {
		        "news.nt_id": $("#ntiD").val()
		    };
		oTable.settings()[0].ajax.data = param;
		oTable.ajax.reload()
	}
	function updateSort(value,nid){
		var $v = $(value);
		layer.yuansu = $v;
		layer.sort = value.innerHTML;
		layer.nid = nid;
		layer.open({
  		  type: 2,
		  area: ['700px', '200px'],
		  fix: false, //不固定
		  maxmin: true,
		  content: $('#baseUrl').attr("href")+'news/toUpdateNewsSort'
		});
	}
	
</script>
</html>
